package cn.net.zidian.api;

import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.net.zidian.bean.AstroBean;
import cn.net.zidian.bean.AstroDetailsBean;
import cn.net.zidian.bean.CiDianBean;
import cn.net.zidian.bean.IPBean;
import cn.net.zidian.bean.IdCardBean;
import cn.net.zidian.bean.ResultBean;
import cn.net.zidian.bean.ShouJiBean;
import cn.net.zidian.bean.TodayBean;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * 仓库
 */
public class ApiRepository {

    private static final String appkey = "7ddb10c1066f2036";

    private static final ApiService apiService = RetrofitClientInstance.getInstance().create(ApiService.class);

    public static Observable<ResultBean<ShouJiBean>> searchShouji(String shouji) {
        Map<String, String> map = new HashMap<>();
        map.put("shouji", shouji);
        map.put("appkey", appkey);
        return apiService.searchPhone(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<ResultBean<IPBean>> searchIP(String ip) {
        Map<String, String> map = new HashMap<>();
        map.put("ip", ip);
        map.put("appkey", appkey);
        return apiService.searchIP(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<ResultBean<IdCardBean>> searchIdCard(String idcard) {
        Map<String, String> map = new HashMap<>();
        map.put("appkey", appkey);
        map.put("idcard", idcard);
        return apiService.searchIdCard(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<ResultBean<List<AstroBean>>> getAstroAll() {
        Map<String, String> map = new HashMap<>();
        map.put("appkey", appkey);
        return apiService.getAstroAll(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<ResultBean<AstroDetailsBean>> getAstroDetails(String astroid) {
        Map<String, String> map = new HashMap<>();
        map.put("astroid", astroid);
        map.put("appkey", appkey);
        return apiService.getAstroDetails(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<ResultBean<List<TodayBean>>> getTodayHistory() {
        Map<String, String> map = new HashMap<>();
        Calendar calendar = Calendar.getInstance();
        int currentMonth = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        map.put("month", String.valueOf(currentMonth));
        map.put("day", String.valueOf(day));
        map.put("appkey", appkey);
        return apiService.getTodayHistory(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    public static Observable<ResultBean<CiDianBean>> getCiDian(String word) {
        Map<String, String> map = new HashMap<>();
        map.put("word", word);
        map.put("appkey", appkey);
        return apiService.getCiDian(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
